package org.infinitest.intellij;

import org.infinitest.InfinitestCore;
import org.infinitest.RuntimeEnvironment;
import org.infinitest.intellij.idea.IdeaCompilationListener;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.junit.Test;

import com.intellij.openapi.compiler.CompilationStatusListener;

public class WhenCompilationCompletes
{
  private Mockery mockery = new Mockery();
  private InfinitestCore mockCore;
  private ModuleSettings moduleSettings = new FakeModuleSettings("test");

  @Test
  public void shouldInvokeUpdateOnCore()
  {
    mockCore = mockery.mock(InfinitestCore.class);
    mockery.checking(new Expectations()
    {
      {
        // TODO More specifically check this parameter
        one(mockCore).setRuntimeEnvironment(with(any(RuntimeEnvironment.class)));
        one(mockCore).update();
      }
    });

    CompilationStatusListener listener = new IdeaCompilationListener(mockCore, moduleSettings);
    listener.compilationFinished(false, 0, 0, null);

    mockery.assertIsSatisfied();
  }
}
